import { forwardRef, useImperativeHandle } from 'react' // react属性
import { Dialog,Toast } from 'antd-mobile' // 三方UI组件
import { getLoveText,getJokeText } from '@/api/index' // 情话 笑话

/* ts类型 */
interface ApiListType {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  [key: string]: any
}

const TextDialog = forwardRef((_props, ref) => {
  /* 工具请求对象 */
  const ApiList: ApiListType = {
    'getLoveText': getLoveText,
    'getJokeText': getJokeText,
  }

  useImperativeHandle(ref, () => ({
    async onDialogText(ApiUrl: string) {
      console.log(ApiUrl);
      Toast.show({
        icon: 'loading',
        content: '加载中…',
        duration: 0,
      })
      try {
        const res = await ApiList[ApiUrl]({ type: 'json' });
        console.log(res);
        Toast.clear()
        Dialog.alert({
          title: res.data.type,
          content: res.data.data.content,
        })

      } catch (error) {
        Toast.clear()
        console.log(error);
      }
    }
  }));


  return (
    <></>
  )
})

export default TextDialog